/*********************************************************************
*
*   DigitalInput.cpp - Digital input class
*
*   Copyright:
*       Software source code by Alex Morozov and Chris D. Locke is
*       licensed under a Creative Commons Attribution-Noncommercial-
*       Share Alike 3.0 United States License
*       (http://creativecommons.org/licenses/by-nc-sa/3.0/us/)
*
*********************************************************************/
#include "StdAfx.h"
#include "DigitalInput.h"

#include "CppBot.h"

/**
 * Create an instance of a DigitalInput.
 * Creates a digital input given a slot and channel. Common creation routine
 * for all constructors.
 */
void DigitalInput::InitDigitalInput(UINT32 slot, UINT32 channel)
{
    m_channel = channel;
    m_slot    = slot;
    init_dio( m_slot, m_channel, false );
}

/**
 * Create an instance of a Digital Input class.
 * Creates a digital input given a channel and uses the default module.
 */
DigitalInput::DigitalInput( UINT32 channel )
{
InitDigitalInput( 4 /* CDL GetDefaultDigitalModule()*/, channel );
}

/**
 * Create an instance of a Digital Input class.
 * Creates a digital input given an channel and module.
 */
DigitalInput::DigitalInput( UINT32 slot, UINT32 channel )
{
InitDigitalInput( slot, channel );
}

/**
 * Free resources associated with the Digital Input class.
 */
DigitalInput::~DigitalInput( )
{
}

/*
 * Get the value from a digital input channel.
 * Retrieve the value of a single digital input channel from the FPGA.
 */
UINT32 DigitalInput::Get( )
{
    return( get_dio( m_slot, m_channel ) ? 1 : 0 );
}

/**
 * @return The GPIO channel number that this object represents.
 */
UINT32 DigitalInput::GetChannel()
{
    return m_channel;
}

